
package com.jf.cloud.multishop.listener;

import com.jf.cloud.api.multishop.bo.OrderChangeShopWalletAmountBO;
import com.jf.cloud.common.rocketmq.config.RocketMqConstant;
import com.jf.cloud.multishop.service.ShopWalletService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @author zz
 */
@Component
@RocketMQMessageListener(topic = RocketMqConstant.ORDER_REFUND_SHOP_TOPIC,consumerGroup = RocketMqConstant.ORDER_REFUND_SHOP_TOPIC)
public class OrderRefundShopConsumer implements RocketMQListener<OrderChangeShopWalletAmountBO> {
    private static final Logger LOGGER = LoggerFactory.getLogger(OrderRefundShopConsumer.class);
    @Autowired
    private ShopWalletService shopWalletService;

    /**
     * 订单退款 商家减少余额
     */
    @Override
    public void onMessage(OrderChangeShopWalletAmountBO orderChangeShopWalletAmountBO) {
        // 如果是待采购，则使用待采购金额计算
        if(Objects.equals(orderChangeShopWalletAmountBO.getWaitPurchase(),1)) {
            LOGGER.info("待采购订单退款，商家减少余额{}", orderChangeShopWalletAmountBO);
            shopWalletService.refundShopAmountByRefundAndWaitPur(orderChangeShopWalletAmountBO);
        }else{
            LOGGER.info("普通订单退款，商家减少余额{}", orderChangeShopWalletAmountBO);
            shopWalletService.refundShopAmountByRefund(orderChangeShopWalletAmountBO);
        }
    }
}
